#include "stdafx.h"
#include <cstdlib>
#include <string>
using namespace std;

const string TOK_CLOSING_COMMENT = "*/";
const string TOK_STARTING_COMMENT = "/*";
const string TOK_OPEN_BRACE = "{";
const string TOK_CLOSE_BRACE = "}";
const string TOK_FUNCTION = "function";
const string TOK_SINGLE_COMMENT = "//";

enum TokenEnum
{
	tNone,
	tOpenBrace,			// {
	tCloseBrace,		// }
	tFunction,			// function
	tStartingComment,	// /*
	tSingleComment,		// //
	tClosingComment		// */
};

class MemberDescription
{
public:
	MemberDescription()
	{
		Description = "";
		Name = "";
		InternalDescription = "";
		Lines = 0;
		StartingAt = 0;
		Complexity = 0;
		parameters = new ArrayList();
	}

	string Description;
	string Name;
	string InternalDescription;
	int Lines;
	int StartingAt;
	int Complexity;
	ArrayList parameters;
};

class FileDescription
{
public:
	FileDescription()
	{
		Description = "";
		Name = "";
		InternalDescription = "";
		Lines = 0;
		StartingAt = 0;
		Complexity = 0;
		Functions = new ArrayList();
		OutputFile = "";
	}

	string FileName;
	int Lines;
	int WithoutComment;
	int Complexity;
	ArrayList Functions;
	string OutputFile;
};

class Status
{
public:
	Status()
	{
		line = "";
		pos = 0;
		braces = 0;
		InFunction = false;
		InComment = false;
		Value = "";
		Desc = new FileDescription();
		func = new MemberDescription();
	}

	string line;
	int pos;
	int braces;
	bool InFunction;
	bool FunctionStarted;
	bool InComment;
	string Value;
	FileDescription Desc;
	MemberDescription func;
};

class JsParser
{
	FileDescription parser(string strHTML);
	bool GetParameters(string strHTML, Status stat);
	TokenEnum GetNextToken(Status stat);
	bool ProcessLine(Status stat);
	string GetFunctionName(Status stat);
	FileDescription AnalizeDirectory(string path, string pattern);
};